package com.lightsh.object;

import org.jbox2d.common.Vec2;

import android.graphics.Canvas;
import android.graphics.Rect;

import com.lightsh.gui.BaseScreen;
import com.lightsh.utility.GeometryUtility;
import com.lightsh.utility.Utility;

public abstract class CircleObject extends SimpleObject{
	protected float mRadius;
	
	public CircleObject(BaseScreen screen, float x, float y, float radius) {
		super(screen, x, y);
		mRadius = radius;
	}
	

	@Override
	public void draw(Canvas canvas, Rect screenRect, float selfScale, float worldScale) {
		if(isVisible() && isInRect(screenRect, selfScale)){
			Vec2 vec2 = getPosition();
			canvas.save();
			rotateCanvas(canvas, mAngle, vec2, screenRect, selfScale, worldScale);
			if(mSprite != null){
				mSprite.draw(canvas, mPaint, (int)((vec2.x - mRadius) / selfScale + mDrawImageOffsetX - screenRect.left), 
						(int)((vec2.y - mRadius) / selfScale + mDrawImageOffsetY - screenRect.top), worldScale);
			} else if(mBitmap != null){
				drawBitmap(canvas, vec2.x - mRadius, vec2.y - mRadius, screenRect, selfScale, worldScale);
			}else{
				canvas.drawCircle((vec2.x / selfScale - screenRect.left) * worldScale, (vec2.y / selfScale - screenRect.top) * worldScale, 
						mRadius / selfScale * worldScale, mPaint);
			}
			canvas.restore();
		}
	}


	@Override
	public boolean isInRect(Rect rect, float selfScale) {
		return GeometryUtility.isCircleInRect(getPosition(), mRadius, rect, selfScale);
	}

	@Override
	public boolean isPointInside(Vec2 point, float worldScale, float screenX, float screenY) {
		return GeometryUtility.isPointInCircle(getPosition(), mRadius, worldScale, screenX, screenY, point);
	}
	
	
}
